package com.supreme.studyserver.service;

import com.supreme.studyserver.entity.Admin;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class UserService {

    private String strCache;

    private Admin globalAdmin;

    // 测试单例bean的代码 开始
    public void newString() {
        strCache = "hello";
    }

    public void printStrCache() {
        System.out.println("strCache: " + strCache);
    }

    public void newAdmin() {
        globalAdmin = new Admin();
    }

    public void printAdmin() {
        System.out.println("printAdmin: " + globalAdmin);
    }
    // 测试单例bean的代码 结束

    public void demoMetadataReader() {
        final SimpleMetadataReaderFactory simpleMetadataReaderFactory = new SimpleMetadataReaderFactory();
        try {
            final MetadataReader metadataReader = simpleMetadataReaderFactory.getMetadataReader("com.supreme.studyserver.service.AuthService");
            final ClassMetadata classMetadata = metadataReader.getClassMetadata();
            System.out.println(classMetadata.getClassName());

            final AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
            for (String annotationType : annotationMetadata.getAnnotationTypes()) {
                System.out.println("annotationType: " + annotationType);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
